﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using RxjhServer.DbClss;

namespace RxjhServer
{
	public partial class UserList : Form
	{
		public UserList()
		{
			this.InitializeComponent();
		}

		private void UserList_Load(object sender, EventArgs e)
		{
			try
			{
				this.listView1.ListViewItemSorter = new ListViewColumnSorter();
				this.listView1.ColumnClick += new ColumnClickEventHandler(ListViewHelper.ListView_ColumnClick);
				foreach (Players current in World.allConnectedChars.Values)
				{
					if (current != null)
					{
						string[] array = new string[21];
						try
						{
							array[0] = current.人物全服ID.ToString();
							array[1] = current.Userid;
							array[2] = current.UserName;
							array[3] = current.Player_Level.ToString();
							array[4] = current.人物_HP.ToString();
							if (current.Client != null)
							{
								array[5] = current.Client.ToString();
							}
							array[6] = current.内网ip;
							array[7] = current.人物坐标_地图.ToString();
							array[8] = current.人物坐标_X.ToString();
							array[9] = current.人物坐标_Y.ToString();
							array[10] = current.FLD_人物基本_攻击.ToString();
							array[11] = current.FLD_追加百分比_攻击.ToString();
							array[12] = current.FLD_人物基本_防御.ToString();
							array[13] = current.FLD_追加百分比_防御.ToString();
							array[14] = current.FLD_装备_追加_气功.ToString();
							array[15] = current.Client.dwStop.ToString();
							array[16] = current.FLD_装备_追加_武器_强化.ToString();
							array[17] = current.FLD_装备_追加_防具_强化.ToString();
							array[18] = current.Player_Job.ToString();
							array[19] = current.FLD_VIP_防御.ToString();
							if (current.是否人物离线挂机)
							{
								array[20] = "离线商店";
							}
							else
							{
								array[20] = "在线";
							}
						}
						catch
						{
							array[0] = current.人物全服ID.ToString();
							array[1] = current.Userid;
							array[2] = current.UserName;
							array[3] = current.Player_Level.ToString();
						}
						this.listView1.Items.Insert(this.listView1.Items.Count, new ListViewItem(array));
					}
				}
			}
			catch (Exception ex)
			{
				Form1.WriteLine(1, "人物列表出错" + ex.Message);
			}
		}

		private void menuItem1_Click(object sender, EventArgs e)
		{
			if (this.listView1.SelectedItems.Count > 0)
			{
				string text = this.listView1.SelectedItems[0].SubItems[2].Text;
				Players players = World.检查玩家name(text);
				if (players != null)
				{
					if (players.Client.挂机)
					{
                        players.OpClient(1);
                        players.Client.DisposedOffline();
                        return;
					}
					players.OpClient(1);
					players.Client.Dispose();
					//players.Client.Disposed();
				}
			}
		}

		private void menuItem2_Click(object sender, EventArgs e)
		{
			if (this.listView1.SelectedItems.Count > 0)
			{
				string text = this.listView1.SelectedItems[0].SubItems[1].Text;
				Players players = World.检查玩家(text);
				if (players != null)
				{
					if (players.Client.挂机)
					{
                        players.OpClient(1);
                        players.Client.DisposedOffline();
                        return;
					}
					players.OpClient(1);
					players.Client.Dispose();
					//players.Client.Disposed();
				}
			}
		}

		private void menuItem3_Click(object sender, EventArgs e)
		{
			if (this.listView1.SelectedItems.Count > 0)
			{
				string text = this.listView1.SelectedItems[0].SubItems[5].Text;
				string sqlCommand = string.Format(" Insert into TBL_BANED values ( '{0}')", text);
				DBA.ExeSqlCommand(sqlCommand, "rxjhaccount");
			}
		}

		private void menuItem4_Click(object sender, EventArgs e)
		{
			if (this.listView1.SelectedItems.Count > 0)
			{
				string text = this.listView1.SelectedItems[0].SubItems[1].Text;
				string sqlCommand = string.Format("UPDATE TBL_ACCOUNT SET FLD_ZT=1 WHERE FLD_ID='{0}'", text);
				DBA.ExeSqlCommand(sqlCommand, "rxjhaccount");
			}
		}

		private void menuItem5_Click(object sender, EventArgs e)
		{
			if (this.listView1.SelectedItems.Count > 0)
			{
				string text = this.listView1.SelectedItems[0].SubItems[2].Text;
				new UserIdList
				{
					username = text
				}.ShowDialog();
			}
		}

		private void listView1_SelectedIndexChanged(object sender, EventArgs e)
		{
		}

		private void menuItem6_Click(object sender, EventArgs e)
		{
			if (this.listView1.SelectedItems.Count > 0)
			{
				string text = this.listView1.SelectedItems[0].SubItems[2].Text;
                RxjhServer.sendmsg.SetName(text);
				sendmsg sendmsg = new sendmsg();
				sendmsg.ShowDialog();
			}
		}

		private void menuItem7_Click(object sender, EventArgs e)
		{
			if (this.listView1.SelectedItems.Count > 0)
			{
				string arg_34_0 = this.listView1.SelectedItems[0].SubItems[2].Text;
				SendItem sendItem = new SendItem();
				sendItem.ShowDialog();
			}
		}
	}
}
